package tags;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.DynamicAttributes;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by hadoop on 17-6-14.
 * 动态属性自定义标签
 */
public class DynaAttrTag extends SimpleTagSupport implements DynamicAttributes{
    private Map<String,Object> map = new HashMap<>();

    @Override
    public void doTag() throws JspException, IOException {
        JspWriter out = getJspContext().getOut();
        out.println("<ol>");
        for(String key : map.keySet()){
            out.println("<li>"+key+" = "+map.get(key)+"</li>");
        }
        out.println("</ol>");
    }

    @Override
    public void setDynamicAttribute(String s, String s1, Object o) throws JspException {
        map.put(s1,o);
    }
}
